package com.nut.lmsc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.lmsc.api.req.CirclePersonQueryReq;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.entity.CirclePerson;
import com.nut.lmsc.mapper.CirclePersonMapper;
import com.nut.lmsc.service.CirclePersonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Slf4j
@Service
public class CirclePersonServiceImpl implements CirclePersonService {

    @Autowired
    private CirclePersonMapper circlePersonMapper;

//    @Override
//    public Result<List<CirclePerson>> list() {
//        LambdaQueryWrapper<CirclePerson> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(CirclePerson::getStatus, 1);
//        queryWrapper.orderByAsc(CirclePerson::getSort);
//        List<CirclePerson> list = circlePersonMapper.selectList(queryWrapper);
//        return Result.ok(list);
//    }

    @Override
    public Result<IPage<CirclePerson>> listPage(CirclePersonQueryReq req) {
        IPage<CirclePerson> list = circlePersonMapper.listPage(req.newPage(), req.getCircleId(),
                req.getName(), req.getMobile(),
                req.getStatus(), req.getRole());
        return Result.ok(list);
    }

    @Override
    public Result<CirclePerson> getById(Integer id) {
        CirclePerson circlePerson = circlePersonMapper.selectById(id);
        if (circlePerson == null) {
            return Result.fail("未找到导航图片信息");
        }
        return Result.ok(circlePerson);
    }

    @Override
    public Result add(CirclePerson circlePerson) {
        circlePersonMapper.insert(circlePerson);
        return Result.ok();
    }

    @Override
    public Result updateById(CirclePerson circlePerson) {
        circlePersonMapper.updateById(circlePerson);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        circlePersonMapper.deleteBatchIds(ids);
        return Result.ok();
    }
}
